#include <string.h>

#include "PluginStdDetailsLib.h"

void *MXSTDMETHOD CreateClassInstance(const char *IID)
{
	void *rc = NULL;

	if(
		strncmp(IID, IPluginStdDetailsLibIID::GUID(),
			IMxPluginBaseIID::IIdSize) == 0
	)
		rc = new PluginStdDetailsLib();
	else if(
		strncmp(IID, IMxPluginLibDetailsIID::GUID(),
			IMxPluginBaseIID::IIdSize) == 0
	)
		rc = new PluginStdDetailsLib();
	else if(
		strncmp(IID, IMxPluginBaseIID::GUID(), IMxPluginBaseIID::IIdSize) == 0
	)
		rc = new PluginStdDetailsLib();

	if(rc) {
		((PluginStdDetailsLib *)rc)->InitInstance();
		((IMxPluginBase *) rc)->DuplicatePtr();
	}

	return rc;
}

PluginStdDetailsLib::PluginStdDetailsLib(void):
	_refCnt(0)
{
}

PluginStdDetailsLib::~PluginStdDetailsLib(void)
{
}

void PluginStdDetailsLib::InitInstance(void)
{
	_LibName = "PluginStdDetailsLib";
	_LibVersion = "1.0.0.6";
	_LibOwnerName = "MxPlugin";
	_LibCopyrightNotice = "New BSD Licence";
	_LibDescription = "Some type of Library";
	_LibID = "1";
	_LibSupportSite = "http://www.mxplugin.org";
	_LibLicenseName = "New BSD Licence";
	_LibLicenseURL = "http://mxplugin.codeplex.com/licence";
	_LibPathFilename = "libplugindetailslib.so";
	_SocketAppID = DefSocketImageProcXGUI::SID();
}

long MXSTDMETHOD PluginStdDetailsLib::DestroyPtr(void)
{
	long cnt = __sync_fetch_and_sub(&_refCnt, 1);
	if(cnt == 0)
		delete this;

	return cnt;
}

long MXSTDMETHOD PluginStdDetailsLib::DuplicatePtr(void)
{
	return __sync_fetch_and_add(&_refCnt, 1);
}

void *MXSTDMETHOD PluginStdDetailsLib::Dynamic_cast(const char *IID)
{
	void *rc = NULL;

	if(
		strncmp(IID, IPluginStdDetailsLibIID::GUID(),
			IMxPluginBaseIID::IIdSize) == 0
	)
		rc = (IPluginStdDetailsLib *) this;
	else if(
		strncmp(IID, IMxPluginLibDetailsIID::GUID(),
			IMxPluginBaseIID::IIdSize) == 0
	)
		rc = (IMxPluginLibDetails *) this;
	else if(
		strncmp(IID, IMxPluginBaseIID::GUID(), IMxPluginBaseIID::IIdSize) == 0
	)
		rc = (IMxPluginBase *) this;

	if(rc)
		((IMxPluginBase *) rc)->DuplicatePtr();

	return rc;
}

const char *MXSTDMETHOD PluginStdDetailsLib::GetInterfaceGUID(void)
{
	return IPluginStdDetailsLibIID::GUID();
}

const char *MXSTDMETHOD PluginStdDetailsLib::GetInterfaceName(void)
{
	return IPluginStdDetailsLibIID::Name();
}

const char *MXSTDMETHOD PluginStdDetailsLib::GetComment(void)
{
	return "hello from PluginStdDetailsLib";
}
